﻿using System.Collections;
using System.Collections.Generic;
using System.Dynamic;

namespace NiuX.LightServer.Extensions
{
    public static class Ext
    {
        public static dynamic ToDynamic(this IDictionary dictionary)
        {
            IDictionary<string, object> dy = new ExpandoObject();
            foreach (object key in dictionary.Keys)
            {
                var val = dictionary[key];
                var dyPropName = key.ToString();
                if (!dy.ContainsKey(dyPropName))
                {
                    dy.Add(dyPropName, val);
                }
            }

            return (ExpandoObject)dy;
        }

        public static IServer AddController<T>(this IServer server) where T : HttpHandlerController
        {
            ControllerManager.Load<T>(server);
            return server;
        }
    }
}
